package com.vivz.baby.config;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = "com.vivz.baby.repository")
@PropertySource({ "classpath:persistence-mysql-aws.properties" })
@ComponentScan({ "com.vivz.baby" })
@Profile("prod")
public class AWSPersistenceJPAConfig extends PersistenceJPAConfig {
	
	@Autowired
	private Environment environment;
	
	@Override
	protected Environment getEnvironment() {
		return environment;
	}
	
	// beans
	
	@Override
	@Bean
	public DataSource dataSource() {
		return super.dataSource();
	}
	
	@Override
	@Bean
	public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
		return super.entityManagerFactory();
	}
	
	@Override
	@Bean
	public PlatformTransactionManager transactionManager(final EntityManagerFactory emf) {
		return super.transactionManager(emf);
	}
	
	@Override
	@Bean
	public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
		return super.exceptionTranslation();
	}
}